/**
 * Property.java
 * 19/05/2011 19:29:11
 */
package model;

import java.beans.PropertyChangeSupport;

/**
 * @author walber
 * 
 */
public class PropertySupport<T> extends PropertyChangeSupport {

	private static final long serialVersionUID = -984492463415408979L;

	/**
	 * Valor de la propiedad
	 */
	private T value;
	/**
	 * notificaciones suspendidas
	 */
	private boolean notificationsSuspended;

	public PropertySupport(T value) {
		super(value);
		this.value = value;
		this.notificationsSuspended = false;
	}

	/**
	 * @return the value
	 */
	public T get() {
		return this.value;
	}

	/**
	 * @param value
	 *            the value to set
	 */
	public void set(T value) {
		if (this.value != value) {
			T old = this.value;
			this.value = value;
			setChanged(old);
		}
	}
	
	/**
	 * Notificar a los listeners sin cambiar el valor de la propiedad.
	 */
	public void setChanged(T old) {
		if (this.notificationsSuspended == false) {
			this.firePropertyChange("", old, value);
		}
	}

	/**
	 * Suspender las notificaciones
	 * 
	 * @param suspend
	 * @return old suspend
	 */
	public boolean suspendNotifications(boolean suspend) {
		boolean ret = this.notificationsSuspended;
		this.notificationsSuspended = suspend;
		return ret;
	}
}
